﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;
using System.Web;
namespace ZLDC.Topo.BLL.Estate
{
    public class lp_Report_Userlist_1
    {
        public lp_Report_Userlist_1()
        { }

                                                                public static string GetUserList(string statrday, string endday, string userid)
        {
            #region
            StringBuilder sb = new StringBuilder();
            decimal cell1 = 0;            decimal cell2 = 0;            decimal cell3 = 0;            if (statrday != "0" && endday != "0")
            {
                string sql = "select lc.Reserve1,lc.Other1,lc.Actual_Goal,Unit,BasisName,sum(SinglePoint) as SinglePoint,userID,sum(lc.Quantity) as Quantity,sum(Actual_Number) as Actual_Number from lp_Configuration lc left join lp_Basis lb on lc.BasisName=lb.Name  where CONVERT(varchar,lc.CreateTime,23)>='" + Convert.ToDateTime(statrday).ToString("yyyy-MM-dd") + "' and CONVERT(varchar,lc.CreateTime,23)<='" + Convert.ToDateTime(endday).ToString("yyyy-MM-dd") + "' and userID=" + userid + " and (lc.Actual_Number>0 or lc.Quantity>0 ) group by BasisName,lc.Actual_Goal,userID,Unit,lc.Other1,lc.Reserve1 order by lc.Other1 desc";
                DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);

                int td1rowcount = 0;                int td2rowcount = 0;                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["Reserve1"].ToString() == "1" || ds.Tables[0].Rows[i]["Other1"].ToString() == "1")
                        {
                            td1rowcount++;
                        }
                    }
                }
                td2rowcount = ds.Tables[0].Rows.Count - td1rowcount;

                int td1 = 0;                int td2 = 0;
                if (ds.Tables[0].Rows.Count > 0)
                {
                    sb.Append("<table id=\"tb1\" width=\"650px\" cellpadding=\"0\" cellspacing=\"1\" border=\"0\">");
                    sb.Append("<caption></caption>");
                    sb.Append("<thead>");
                    sb.Append("<tr>");
                    sb.Append("<th align=\"center\" width=\"80\"  class=\"th\">");
                    sb.Append("");
                    sb.Append("</th>");
                    sb.Append("<th align=\"center\" width=\"80\"  class=\"th\">");
                    sb.Append("工作内容");
                    sb.Append("</th>");
                    sb.Append("<th align=\"center\" width=\"70px\"  class=\"th\">");
                    sb.Append("完成量");
                    sb.Append("</th>");
                    sb.Append("<th align=\"center\" width=\"70px\"  class=\"th\">");
                    sb.Append("实际得分");
                    sb.Append("</th>");
                    sb.Append("<th align=\"center\" width=\"70px\"  class=\"th\">");
                    sb.Append("要求得分");
                    sb.Append("</th>");

                    sb.Append("</tr>");
                    sb.Append("</thead>");
                    sb.Append("<tbody>");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["Reserve1"].ToString() == "1" || ds.Tables[0].Rows[i]["Other1"].ToString() == "1")
                        {
                            td1++;
                            sb.Append("<tr style='color:#9B1F07'>");
                            if (td1 == 1)
                            {
                                sb.Append("<td class=\"td\" rowspan=\""+td1rowcount+"\">已分配工作");
                            }
                           
                        }
                        else
                        {
                            td2++;
                            sb.Append("<tr>");
                            if (td2 == 1)
                            {
                                sb.Append("<td class=\"td\"  rowspan=\"" + td2rowcount + "\">未分配完成工作 ");
                            }
                        }
                        
                        sb.Append(" </td>");
                        sb.Append("<td class=\"td\" >");
                        sb.Append("<div style='cursor:pointer;text-decoration: underline' onclick=\"fkqi(" + ds.Tables[0].Rows[i]["userID"].ToString() + ",'" + ds.Tables[0].Rows[i]["BasisName"].ToString() + "')\">" + ds.Tables[0].Rows[i]["BasisName"].ToString());

                        int quantity = 0;
                        if (!Int32.TryParse(ds.Tables[0].Rows[i]["Quantity"].ToString(), out quantity))
                            quantity = 0;

                        if (quantity==0)
                        {
                            sb.Append("(" + ds.Tables[0].Rows[i]["unit"].ToString() + ")");
                        }
                        else
                        {
                            sb.Append(ds.Tables[0].Rows[i]["Quantity"].ToString());                      
                            sb.Append(ds.Tables[0].Rows[i]["unit"].ToString());
                        }
                        sb.Append(" </div></td>");
                        sb.Append("<td class=\"td\">");
                                                                        sb.Append(ds.Tables[0].Rows[i]["Actual_Number"].ToString());
                        cell1 += Convert.ToDecimal(ds.Tables[0].Rows[i]["Actual_Number"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["Actual_Number"].ToString());
                        sb.Append("</td>");
                        if (ds.Tables[0].Rows[i]["Reserve1"].ToString() == "1" || ds.Tables[0].Rows[i]["Other1"].ToString() == "1")
                        {
                            sb.Append("<td class=\"td\" style='color:#48A1EF'>");
                        }
                        else
                        {
                            sb.Append("<td class=\"td\">");
                        }
                        sb.Append(ds.Tables[0].Rows[i]["Actual_Goal"].ToString());
                        cell2 += Convert.ToDecimal(ds.Tables[0].Rows[i]["Actual_Goal"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["Actual_Goal"].ToString());
                        sb.Append("</td>");
                        if (ds.Tables[0].Rows[i]["Reserve1"].ToString() == "1" || ds.Tables[0].Rows[i]["Other1"].ToString() == "1")
                        {
                            sb.Append("<td class=\"td\" style='color:#299129'>");
                        }
                        else
                        {
                            sb.Append("<td class=\"td\">");
                        }
                        sb.Append(ds.Tables[0].Rows[i]["SinglePoint"].ToString());
                        cell3 += Convert.ToDecimal(ds.Tables[0].Rows[i]["SinglePoint"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["SinglePoint"].ToString());
                        sb.Append("</td>");
                        sb.Append("</tr>");
                    }
                    sb.Append("<tr style='color:red'>");
                    sb.Append("<td>");
                   
                    sb.Append("</td>");
                    sb.Append("<td>");
                    sb.Append("总计:");
                    sb.Append("</td>");
                    sb.Append("<td>");
                    sb.Append(cell1);
                    sb.Append("</td>");
                    sb.Append("<td>");
                    sb.Append(cell2);
                    sb.Append("</td>");
                    sb.Append("<td>");
                    sb.Append(cell3);
                    sb.Append("</td>");
                    sb.Append("</tr>");
                    sb.Append("<tr style='color:red'>");
                    sb.Append("<td colspan=\"5\">");
                    sb.Append(ZLDC.Topo.BLL.Estate.lp_myListUrl.returnUrl(userid));
                    sb.Append("</td>");
                    sb.Append("</tr>");
                    sb.Append("</tbody>");
                    sb.Append("</table>");
                }

            }
            return sb.ToString();
            #endregion
        }

                                                                public static string GetNum(string typename,string userid,string daytime)
        {
            string sql="select "+ZLDC.Topo.BLL.Estate.lp_Basis.Gett_quantification_name(typename);
            sql+=" from t_quantification where salesmanId="+userid+" and countDate='"+daytime+"'";
            DataSet ds=ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            if(ds.Tables.Count>0)
            if(ds.Tables[0].Rows.Count>0)
            {
                return ds.Tables[0].Rows[0][0].ToString();
            }
            return "0";
        }
       
    }
}
